unit u_thread_ecoute;

interface

uses IdTCPClient,
     IdContext,
     sysutils,
     IdTCPConnection,
     classes;

type

  ecoute = class(TThread)
    private

      client : TIdTCPClient;
      client_list : Array of string;

  public
    procedure execute; override;
    constructor create(client_ : TIdTCPClient);
  end;

implementation

uses u_engine, u_player;

  constructor ecoute.create(client_ : TIdTCPClient);
    begin
      inherited create(false);
      client := client_;
    end;

  procedure ecoute.Execute;
  var
    i,j : integer;
    msg : string;
    s1, s2, s3, s4, s5 : string;
    p1, p2, p3, p4, p5, p6, p7 : integer;
    begin
      try
        while not Terminated do
          begin
            repeat
              msg := client.IOHandler.ReadLn;
            until (msg <> '') or Terminated;
            if msg = '#msg' then
              begin
                s1 := client.IOHandler.ReadLn;
                myplayer.mychat.add_text(s1);
              end
              else
              if msg = '#newposjoueur' then
                begin
                  p1 := StrToInt(client.IOHandler.ReadLn);
                  p2 := StrToInt(client.IOHandler.ReadLn);
                  p3 := StrToInt(client.IOHandler.ReadLn);
                  p4 := StrToInt(client.IOHandler.ReadLn);
                  p5 := StrToInt(client.IOHandler.ReadLn);
                  p6 := StrToInt(client.IOHandler.ReadLn);
                  myplayer.myreseau.change_pos(p1, p2, p3, p4, p5, p6);
                end
                else
                if msg = '#newclient' then
                  begin
                    s1 := client.IOHandler.ReadLn;
                    p1 := StrToInt(client.IOHandler.ReadLn);
                    p2 := StrToInt(client.IOHandler.ReadLn);
                    p3 := StrToInt(client.IOHandler.ReadLn);
                    myplayer.myreseau.add_player(p1, p2, p3, s1);
                  end
                  else
                  if msg = '#delclient' then
                    begin
                      s1 := client.IOHandler.ReadLn;
                      myplayer.myreseau.del_player_name(s1);
                    end
                    else
                    if msg = '#ennmove' then
                      begin
                        p1 := StrToInt(client.IOHandler.ReadLn);
                        p2 := StrToInt(client.IOHandler.ReadLn);
                        p3 := StrToInt(client.IOHandler.ReadLn);
                        p4 := StrToInt(client.IOHandler.ReadLn);
                        p5 := StrToInt(client.IOHandler.ReadLn);
                        p6 := StrToInt(client.IOHandler.ReadLn);
                        myplayer.myreseauennemis.change_ennemi_pos(p1, p2, p3, p4, p5, p6);
                      end
                      else
                      if msg = '#enndelpos' then
                        begin
                          p1 := StrToInt(client.IOHandler.ReadLn);
                          p2 := StrToInt(client.IOHandler.ReadLn);
                          p3 := StrToInt(client.IOHandler.ReadLn);
                          myplayer.myreseauennemis.del_ennemi_pos(p1, p2, p3);
                        end
                          else
                          if msg = '#hitjoueur' then
                            begin
                              p1 := StrToInt(client.IOHandler.ReadLn);
                              p2 := StrToInt(client.IOHandler.ReadLn);
                              p3 := StrToInt(client.IOHandler.ReadLn);
                              p4 := StrToInt(client.IOHandler.ReadLn);
                              p5 := StrToInt(client.IOHandler.ReadLn);
                              p6 := StrToInt(client.IOHandler.ReadLn);
                              p7 := StrToInt(client.IOHandler.ReadLn);
                              if (p4 = myplayer.get_x) and (p5 = myplayer.get_y) and (p6 = myplayer.etage) then
                                myplayer.carac.vie.actuel := myplayer.carac.vie.actuel- p7;
                              myplayer.particle.add_part_player(100, p1, p2, p4, p5);
                              //ajouter ici appel à la fonction de particules et de touchage du joueur s'il y a lieu
                            end
                            else
                            if msg = '#addobj' then
                              begin
                                p1 := StrToInt(client.IOHandler.ReadLn);
                                p2 := StrToInt(client.IOHandler.ReadLn);
                                p3 := StrToInt(client.IOHandler.ReadLn);
                                s1 := client.IOHandler.ReadLn;
                                s2 := client.IOHandler.ReadLn;
                                s3 := client.IOHandler.ReadLn;
                                s4 := client.IOHandler.ReadLn;
                                s5 := client.IOHandler.ReadLn;
                                //mymesh.ajout_obj();
                                //ajout de la fonction d'ajout d'objet.................
                              end
                              else
                              if msg = '#delobj' then
                                begin
                                  p1 := StrToInt(client.IOHandler.ReadLn);
                                  p2 := StrToInt(client.IOHandler.ReadLn);
                                  p3 := StrToInt(client.IOHandler.ReadLn);
                                  //mymesh.suppr_obj_res(p1, p2, p3);
                                  //Ajouter la fonction de suppression des objets
                                end
                                else
                                if msg = '#newennemi' then
                                  begin                                   
                                    p1 := StrToInt(client.IOHandler.ReadLn);
                                    p2 := StrToInt(client.IOHandler.ReadLn);
                                    p3 := StrToInt(client.IOHandler.ReadLn);
                                    s1 := client.IOHandler.ReadLn;
                                    //Ajouter les ennemis au démarrage...
                                    myplayer.myreseauennemis.add_ennemi(p1, p2, p3, s1);
                                  end;
                                                                                                                           
          end;
      except
      On E:Exception do
        myplayer.mychat.add_text(E.Message);
      end;
    end;


end.

